/*
 * $Id: ShellApp.h,v 1.6 2007/06/21 10:49:01 baconevi Exp $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _SHELLAPP_CLASS_
#define _SHELLAPP_CLASS_

#include <xp/sys/Daemon.hpp>

class ShellApp: public xp::sys::UnpausableDaemon
{
public:
	ShellApp ();
	virtual ~ShellApp ();

#ifdef _WIN32	
	void setChild (bool child);
#endif

	int run ();
	int stop ();
	int shutdown ();

	void handleSignal (int sig);

protected:
	bool stop_requested;

#ifdef _WIN32
	PROCESS_INFORMATION proc_info;
	bool child;
#else
	xp_pid_t parent_pid;
	xp_pid_t nanny_pid;
	xp_pid_t child_pid;
#endif

	void setup_signal_handlers ();
	void restore_signal_handlers ();
	int  run_nanny ();
	int  run_main_task ();
	void load_ini_file ();
};

#endif
